/*
 * @Author: wurangkun
 * @Date: 2024-06-01 19:48:22
 * @LastEditTime: 2024-06-01 20:05:19
 * @LastEditors: wurangkun
 * @FilePath: \my-app\hooks\useMySheetStyle.ts
 * @Description: 
 */
import { StyleSheet } from "react-native";
import { px2dp } from "./computedPx2Pd";

// @ts-ignore
let MyStyleSheet: typeof StyleSheet = {
  create(style) {
    let s = { ...style };
    // 目前仅对以下的属性进行处理

    for (let outKey in s) {
      for (let innerKey in s[outKey]) {
        if (keyNameList.includes(innerKey) &&
          // @ts-ignore
          typeof s[outKey][innerKey] == "number") {
          // @ts-ignore
          s[outKey][innerKey] = px2dp(s[outKey][innerKey]);
        }
      }
    }
    return StyleSheet.create(s);
  },
};


const keyNameList = [
  "width",
  "minWidth",
  "maxWidth",
  "height",
  "minHeight",
  "maxHeight",
  "borderRadius",
  "borderBottomWidth",
  "borderBottomStartRadius",
  "borderBottomRightRadius",
  "borderBottomLeftRadius",
  "borderBottomEndRadius",
  "borderTopWidth",
  "borderTopStartRadius",
  "borderTopRightRadius",
  "borderTopLeftRadius",
  "borderTopEndRadius",
  "borderWidth",
  "borderTopWidth",
  "borderRightWidth",
  "borderBottomWidth",
  "borderLeftWidth",
  "margin",
  "marginTop",
  "marginBottom",
  "marginLeft",
  "marginRight",
  "marginHorizontal",
  "marginVertical",
  "padding",
  "paddingTop",
  "paddingRight",
  "paddingBottom",
  "paddingLeft",
  "paddingHorizontal",
  "paddingVertical",
  "top",
  "right",
  "bottom",
  "left",
  "fontSize",
  "lineHeight"
];

export default MyStyleSheet;